package com.vviton.zyhj.common.utils.idgen;

import java.util.Random;
import java.util.UUID;

/**
 * 随机数生成器
 */
public class RandomKey {

    private static Random random = new Random();

    /*
     * uuid，不会出现重复
     */
    public static String getUUID() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    /*
     * 已时间毫秒为基数，增加6位随机数，可能出现小概率毫秒级冲突
     */
    public static long getKey() {

        int bit = 6;
        long key = System.currentTimeMillis() * (int) Math.pow(10, bit);
        for (int i = 0; i < bit; i++) {
            key += ((int) Math.pow(10, bit - 1 - i)) * random.nextInt(10);
        }
        return key;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(getKey());
        }

    }
}
